﻿using System.ComponentModel.Composition;
using System.Waf.Applications;
using System.Windows.Controls;
using HighLandirect.Applications.ViewModels;
using HighLandirect.Applications.Views;
using HighLandirect.Domain;

namespace HighLandirect.Presentation.Views
{
    [Export(typeof(ICustomerListView))]
    public partial class CustomerListView : UserControl, ICustomerListView
    {
        public CustomerListView()
        {
            InitializeComponent();
        }


        private CustomerListViewModel ViewModel { get { return this.GetViewModel<CustomerListViewModel>(); } }


        private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (object o in e.RemovedItems)
            {
                var customer = o as Customer;
                if (customer != null)
                    ViewModel.SelectedCustomers.Remove(customer);
            }
            foreach (object o in e.AddedItems)
            {
                var customer = o as Customer;
                if (customer != null)
                    ViewModel.SelectedCustomers.Add(customer);
            }
        }

        private void LabelCheckBox_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            foreach (var customer in this.ViewModel.SelectedCustomers)
            {
                customer.Label = e.RoutedEvent.Name == "Checked";
            }
        }

        private void DeleteCheckBox_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            foreach (var customer in this.ViewModel.SelectedCustomers)
            {
                customer.Delete = e.RoutedEvent.Name == "Checked";
            }
        }

        private void ShowDeletedData(object sender, System.Windows.RoutedEventArgs e)
        {
            this.ViewModel.ShowDeletedData();
        }

        private void HideDeletedData(object sender, System.Windows.RoutedEventArgs e)
        {
            this.ViewModel.HideDeletedData();
        }

    }
}
